package com.ms.education.statistics.jobs;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.ms.education.ServerUtils;
import com.ms.education.constant.OrderConstant;
import com.ms.education.exceptionHandler.EduException;
import com.ms.education.statistics.service.feign.OrderFeignService;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>Project:education-DeleteExpireOrderJob
 * <p>Powered by ms on 2023-02-17 03:20:05
 *
 * @author ms
 * @version 1.0
 * @since 1.8
 */
@Slf4j
public class DeleteExpireOrderJob implements SimpleJob {

    private OrderFeignService orderFeignService;

    public DeleteExpireOrderJob(OrderFeignService orderFeignService){
        this.orderFeignService=orderFeignService;
    }

    @Override
    public void execute(ShardingContext shardingContext) {
        log.info("{}:删除超过{}秒没有支付的订单的任务开始", ServerUtils.SERVER_IP_PORT,OrderConstant.expiredTime);
        Boolean success = orderFeignService.deleteExpiredOrder().getSuccess();
        if (!success){
            throw new EduException(20001,ServerUtils.SERVER_IP_PORT+"删除超过"+OrderConstant.expiredTime+"秒没有支付的订单的任务失败，转交其他服务执行");
        }
        log.info("{}:删除超过{}秒没有支付的订单的任务结束", ServerUtils.SERVER_IP_PORT,OrderConstant.expiredTime);

    }
}
